package com.penghaisoft.microwms.product.web.controller.insidewarehouse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.wms.model.ProCountingDifference;
import com.penghaisoft.microwms.product.service.IProCountingDifferenceService;


@RestController
@RequestMapping(value = "/proCountingDifference")
@Slf4j
public class ProCountingDifferenceController extends BaseController {
	
		@Autowired
		private IProCountingDifferenceService proCountingDifferenceService;

	  /**
	   * 新增记录
	   * @param proCountingDifference
	   * @return
	   */
		@PostMapping("c")
		public TransResult create(ProCountingDifference proCountingDifference) {
			proCountingDifference.preInsert();
			Resp resp =  proCountingDifferenceService.create(proCountingDifference);
			return fromResp(resp);
		}

	  /**
	   * 删除记录（逻辑删除active_flag=0)
	   * @param proCountingDifference
	   * @return
	   */
		@PostMapping("d")
		public TransResult delete(ProCountingDifference proCountingDifference) {
			proCountingDifference.preUpdate();
			Resp resp =  proCountingDifferenceService.delete(proCountingDifference);
			return fromResp(resp);
		}

	  /**
	   * 查询列表
	   * @param pager
	   * @return
	   */
		@PostMapping("list")
		public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows,ProCountingDifference proCountingDifference) {
			Pager<ProCountingDifference> result = proCountingDifferenceService.findListByCondition(page,rows,proCountingDifference);
			return success(result);
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@GetMapping("r/{id}")
		public TransResult queryById(@PathVariable String id) {
			ProCountingDifference  proCountingDifference = proCountingDifferenceService.findById(id);
			return success(proCountingDifference);
		}

	  /**
	   * 修改记录
	   * @param proCountingDifference
	   * @return
	   */
		@PostMapping("u")
		public TransResult update(ProCountingDifference proCountingDifference) {
			proCountingDifference.preUpdate();
			Resp resp =  proCountingDifferenceService.update(proCountingDifference);
	    	return fromResp(resp);
		}

}
